n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = -1
for i in range(n):
    ans = max(ans, min(a[i] - 1, i + 1))
print(ans)